package databaseVersionControl.domain.dialect.h2;

import databaseVersionControl.domain.db.DataType;
import databaseVersionControl.domain.dialect.Dialect;

public class H2Dialect extends Dialect {

	@Override
	protected void setup() {
		registerColumnType(DataType.STRING, "VARCHAR");
		registerColumnType(DataType.LONG, "BIGINT");
		registerColumnType(DataType.INTEGER, "INT");
		registerColumnType(DataType.BOOLEAN, "BOOLEAN");
		registerColumnType(DataType.DATE, "DATE");
		registerColumnType(DataType.TIME, "TIME");
		registerColumnType(DataType.TIMESTAMP, "TIMESTAMP");
	}

	@Override
	public String getNextSequenceValue(String sequenceName) {
		return String.format("CALL NEXTVAL('%s')", sequenceName);
	}

	@Override
	public String checkExistTable(String tableName) {
		return String.format("SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = '%s'", tableName);
	}

	@Override
	public String checkExistSequence(String sequenceName) {
		return String.format("SELECT SEQUENCE_NAME from INFORMATION_SCHEMA.SEQUENCES where SEQUENCE_NAME = '%s'", sequenceName);
	}
	
}